﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace LiskovSubstitutionLibrary
{
    public class Purity2
    {
        protected static int[] StaticArray = new int[10];

        public static object StaticProperty { get; set; }

        public object Property { get; set; }

        public object Property2 { get; set; }

        public static event EventHandler StaticEvent;

        public event EventHandler InstanceEvent;

        public static object StaticField;

        protected object BaseMember;

        private readonly object[] _items = new object[5];
        public object this[int key]
        {
            get
            {
                return _items[key];
            }
            set
            {
                _items[key] = value;
            }
        }

        public void ModifyOwnBaseField()
        {
            BaseMember = new object();
        }

        public void SetItemToStaticArray(int index, int item)
        {
            if (index < 0 || index >= StaticArray.Length)
            {
                throw new ArgumentOutOfRangeException();
            }
            StaticArray[index] = item;
        }

        public void RaiseEvents()
        {
            var ev = StaticEvent;
            if (ev != null)
            {
                ev(null, null);
            }
            ev = InstanceEvent;
            if (ev != null)
            {
                ev(null, null);
            }
        }

        public void UseCollections()
        {
            var stack = new Stack<int>();
            stack.Push(17);
            Console.WriteLine(stack.Peek());
            stack.Pop();
            var queue = new Queue<int>();
            queue.Enqueue(21);
            Console.WriteLine(queue.Peek());
            queue.Dequeue();
            var linkedList = new LinkedList<int>();
            linkedList.AddFirst(28);
            Console.WriteLine(linkedList.Find(28));
            linkedList.Clear();
            IList<int> ilist = new List<int>();
            ilist.Insert(0, 23);
            Console.WriteLine(ilist.IndexOf(23));
            ilist.RemoveAt(0);
            List<int> list = (List<int>)ilist;
            list.Insert(0, 23);
            Console.WriteLine(list.Contains(23));
            list.RemoveAt(0);
            ICollection<int> collection = ilist;
            collection.Add(24);
            Console.WriteLine(collection.Contains(23));
            collection.Clear();
            var arrayList = new ArrayList();
            arrayList.Add(28);
            Console.WriteLine(arrayList.Clone());
            arrayList.Clear();
            var sortedList = new SortedList();
            sortedList.Add(28, 29);
            Console.WriteLine(sortedList.Clone());
            sortedList.Clear();
            var sortedListg = new SortedList<int, long>();
            sortedListg.Add(28, 29);
            Console.WriteLine(sortedListg.Count);
            sortedListg.Clear();
            var sortedSet = new SortedSet<int>();
            sortedSet.Add(28);
            Console.WriteLine(sortedSet.Count);
            sortedSet.Clear();
            var sortedDictionary = new SortedDictionary<int, long>();
            sortedDictionary.Add(28, 29);
            Console.WriteLine(sortedDictionary.Count);
            sortedDictionary.Clear();
        }

        public void CopyFrom(Purity2 source)
        {
            Property = source.Property;
            Property2 = source.Property2;
        }

        public void CopyTo(Purity2 target)
        {
            target.Property = Property;
            target.Property2 = Property2;
        }
    }
}
